package com.huayanginfo.saas.export;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ResourceReader {
	/**
	 * 默认以utf-8读取文件
	 * @param resource
	 * @return
	 * @throws IOException
	 */
	public static String getString(String resourceName, String charset) throws IOException {
		if (charset == null) charset = "UTF-8";
		InputStream inputStream = ResourceReader.class
				.getResourceAsStream(resourceName);
		BufferedReader bufferedReader = new BufferedReader(
				new InputStreamReader(inputStream, charset));
		StringBuilder stringBuilder = new StringBuilder();
		char[] buffer = new char[1024];
		int size = 0;
		while ((size = bufferedReader.read(buffer)) != -1) {
			stringBuilder.append(String.valueOf(buffer, 0, size));
		}
		return stringBuilder.toString();
	}
}
